/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Hochschule Heilbronn
 * License Type: Academic
 */
package de.hhn.pmt.tour.u6;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;

public class TourDAO {
	public static Tour loadTourByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadTourByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour getTourByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getTourByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadTourByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour getTourByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getTourByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Tour) session.load(de.hhn.pmt.tour.u6.Tour.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour getTourByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Tour) session.get(de.hhn.pmt.tour.u6.Tour.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Tour) session.load(de.hhn.pmt.tour.u6.Tour.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour getTourByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Tour) session.get(de.hhn.pmt.tour.u6.Tour.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryTour(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryTour(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryTour(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryTour(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour[] listTourByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listTourByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour[] listTourByQuery(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listTourByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryTour(PersistentSession session, String condition,
			String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Tour as Tour");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryTour(PersistentSession session, String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Tour as Tour");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tour", lockMode);
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour[] listTourByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		try {
			List list = queryTour(session, condition, orderBy);
			return (Tour[]) list.toArray(new Tour[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour[] listTourByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			List list = queryTour(session, condition, orderBy, lockMode);
			return (Tour[]) list.toArray(new Tour[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadTourByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByQuery(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadTourByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour loadTourByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		Tour[] tours = listTourByQuery(session, condition, orderBy);
		if (tours != null && tours.length > 0)
			return tours[0];
		else
			return null;
	}

	public static Tour loadTourByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		Tour[] tours = listTourByQuery(session, condition, orderBy, lockMode);
		if (tours != null && tours.length > 0)
			return tours[0];
		else
			return null;
	}

	public static java.util.Iterator iterateTourByQuery(String condition,
			String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateTourByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateTourByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateTourByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateTourByQuery(
			PersistentSession session, String condition, String orderBy)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Tour as Tour");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateTourByQuery(
			PersistentSession session, String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Tour as Tour");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tour", lockMode);
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Tour createTour() {
		return new de.hhn.pmt.tour.u6.Tour();
	}

	public static boolean save(de.hhn.pmt.tour.u6.Tour tour)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance()
					.saveObject(tour);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean delete(de.hhn.pmt.tour.u6.Tour tour)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().deleteObject(
					tour);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(de.hhn.pmt.tour.u6.Tour tour)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.Station[] lStations = tour.station.toArray();
			for (int i = 0; i < lStations.length; i++) {
				lStations[i].tour.remove(tour);
			}
			de.hhn.pmt.tour.u6.RegistrierterBenutzer[] lTeilnehmers = tour.teilnehmer
					.toArray();
			for (int i = 0; i < lTeilnehmers.length; i++) {
				lTeilnehmers[i].tour.remove(tour);
			}
			de.hhn.pmt.tour.u6.Location[] lLocationss = tour.locations
					.toArray();
			for (int i = 0; i < lLocationss.length; i++) {
				lLocationss[i].tours.remove(tour);
			}
			return delete(tour);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(de.hhn.pmt.tour.u6.Tour tour,
			org.orm.PersistentSession session) throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.Station[] lStations = tour.station.toArray();
			for (int i = 0; i < lStations.length; i++) {
				lStations[i].tour.remove(tour);
			}
			de.hhn.pmt.tour.u6.RegistrierterBenutzer[] lTeilnehmers = tour.teilnehmer
					.toArray();
			for (int i = 0; i < lTeilnehmers.length; i++) {
				lTeilnehmers[i].tour.remove(tour);
			}
			de.hhn.pmt.tour.u6.Location[] lLocationss = tour.locations
					.toArray();
			for (int i = 0; i < lLocationss.length; i++) {
				lLocationss[i].tours.remove(tour);
			}
			try {
				session.delete(tour);
				return true;
			} catch (Exception e) {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean refresh(de.hhn.pmt.tour.u6.Tour tour)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.refresh(tour);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean evict(de.hhn.pmt.tour.u6.Tour tour)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.evict(tour);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

}
